//
//  PassWordView.m
//  JiFengDaRen
//
//  Created by zhuchao on 16/10/25.
//  Copyright © 2016年 SH_iOS. All rights reserved.
//

#import "PassWordView.h"

@implementation PassWordView
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        UIView *view0=[[UIView alloc]initWithFrame:self.frame];
        view0.backgroundColor= UIColorFromRGB(0x000000);
        view0.alpha=0.7;
        [self addSubview:view0];
        
        UIButton *disbtn=[UIButton buttonWithType:UIButtonTypeCustom];
        disbtn.frame=CGRectMake(ScreenWidth-__I6Width(40),__I6Height(30),__I6Width(30),__I6Width(30));
        [disbtn setBackgroundImage:[UIImage imageNamed:@"关闭.png"] forState:UIControlStateNormal];
        disbtn.contentMode=UIViewContentModeScaleAspectFit;
        [disbtn addTarget:self action:@selector(disbtnAction) forControlEvents:UIControlEventTouchUpInside];
        [view0 addSubview:disbtn];
        
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake((ScreenWidth- __I6Width(300))/2,__I6Height(200),__I6Width(300), __I6Height(100))];
        view.layer.cornerRadius=__I6Width(5);
        view.backgroundColor=[UIColor whiteColor];
        [self addSubview:view];
        self.tip=[[UILabel alloc]initWithFrame:CGRectMake(0,__I6Height(15), view.frame.size.width, __I6Height(15))];
        self.tip.text = @"请输入支付密码";
        self.tip.font= KBoldFont(__I6Width(15));
        self.tip.textColor= UIColorFromRGB(0x000000);
        self.tip.textAlignment=NSTextAlignmentCenter;
        [view addSubview: self.tip];
        self.password = [[TTPasswordView alloc] initWithFrame:CGRectMake((view.frame.size.width-__I6Width(256))/2,__I6Height(40),__I6Width(256),__I6Height(37))];
        self.password.textField.keyboardType = UIKeyboardTypeNumberPad;
        self.password.elementCount = 6;
        self.password.elementColor= UIColorFromRGB(0xd5d5d5);
        [view addSubview:self.password];
        
        
        __weak PassWordView *weakself = self;
        self.password.passwordBlock = ^(NSString *password) {
            if (password.length==6) {
                if (self.delegate&&[self.delegate respondsToSelector:@selector(useStoreCode:)]) {
                    [weakself.delegate useStoreCode:password];
                }
            }
        };

    }
    return self;
}
- (void)disbtnAction
{
    if (self.delegate&&[self.delegate respondsToSelector:@selector(disAction)]) {
        [self.delegate disAction];
    }
    
}
@end
